<?php
/**
 * 
 * @author tangbl
 * 
 */
class CommentAction extends CommonAction {
	
	public function _initialize() {
		parent::_initialize();
		parent::_initmenu();	
	}
	
	/**
	 * 列表
	 */
	public function index() {
		if(IS_AJAX){
			
			import('ORG.Util.Page');
			$model     = D("Comment");
			
			$orderDesc = $this->_get("orderDirection","trim","desc");;
			$orderName = $this->_get("orderName","trim","addtime");
			$pageNum   = $this->_get("pageNum","intval",C('web_admin_pagenum'));
			$nowPage   = $this->_get("p","intval",1);
			
			$map       = unescape($this->_get("where"));
			$map       = "1=1 ".$map;
			$count     = $model->where($map)->count();
			$Page      = new Page($count);
			$list      = $model->where($map)->order($orderName.' '.$orderDesc)
						 ->field("description,content",true)->page($nowPage.','.$pageNum)->select();
			$totalPage = ceil($count/$pageNum);
			C('web_admin_pagenum',$pageNum);
			
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'rows'=>array(),'totalPage'=>$totalPage);
			$upd       = L('cfg_list_itf_btn_modify');
			$del       = L('cfg_list_itf_btn_delete');
			foreach($list AS $row){
				
				if($row['ischecked']==1){
					$class = "btn";
				}else{
					$class = "btn green checkOne";
				}
				
				$entry = array('id'=>$row['id'],
					'cell'=>array(
						'id'       => $row['id'],
						'title'    => $row['title'],
						'phone'    => $row['mobile'],
						'realname' => $row['realname'],
						'ischecked'=> $row['ischecked'],
						'addtime'  => date('Y-m-d H:i:s',$row['addtime']),
						'deal'=>'
						 <a href="#" class="'.$class.'" data-id="'.$row['id'].'" title="'.L('art_form_ele_edit').'"><i class="icon-check"></i></a>
						 <a href="#" class="btn red icn-only delAlone" title="'.$del.'" data-id="'.$row['id'].'"><i class="icon-remove"></i></a> '
					),
				);
				$jsonData['rows'][] = $entry;
			}
			$this->ajaxReturn($jsonData,'JSON');
			
		}else{
			$this->display();
		}
	}
	
	/**
	 * 删除
	 */
	public function del(){
		
		$param = array(
			"reply"  => false,
		);
		parent::do_del("Comment",true,$param);
	}
	
	/**
	 * 审核评论
	 */
	public function audit(){
		
		$model = M("Comment");
		$id    = $this->_param("id","",0);
		
		if($id){
			
			$map['ischecked'] = 1;
			$where = "id in ($id)";
			
			$data = $model->where($where)->save($map);
			$this->ajaxReturn($data);
			
		}else{
			$data = array("status"=>0,"info"=>"审核失败，请稍后重试");
			$this->ajaxReturn($data);
		}
	}
	
}
?>